/**
 * 
 */
package leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhong
 *
 */
public class SelfDividingNumbers {
	public List<Integer> selfDividingNumbers(int left, int right) {
		List<Integer> res = new ArrayList<>();
		for (int i = left; i <= right; i++) {
			if (divisible(i)) {
				res.add(i);
			}
		}
		return res;
	}

	private boolean divisible(int i) {
		int tmp = i;
		while (tmp != 0) {
			int x = tmp % 10;
			tmp /= 10;
			if (x == 0 || i % x != 0) {// 如果当前为0或者不能整除
				return false;
			}
		}
		return true;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int left = 1, right = 22;
		System.out.println(new SelfDividingNumbers().selfDividingNumbers(left, right));
	}

}
